!-------------------------------------------------------------LICENSE--------------------------------------------------------------!
!                                                                                                                                  !
!The MAP code is written in Fortran language for magnetohydrodynamics (MHD) calculation with the adaptive mesh refinement (AMR)    !
!and Message Passing Interface (MPI) parallelization.                                                                              !
!                                                                                                                                  !
!Copyright (C) 2012                                                                                                                !
!Ronglin Jiang                                                                                                                     !
!rljiang@ssc.net.cn                                                                                                                !
!585 Guoshoujing Road. Pudong, Shanghai, P.R.C. 201203                                                                             !
!                                                                                                                                  !
!This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License         !
!as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.             !
!                                                                                                                                  !
!This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of    !
!MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.                        !
!                                                                                                                                  !
!You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software     !
!Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.                                                   !
!                                                                                                                                  !
!-------------------------------------------------------------LICENSE--------------------------------------------------------------!

!==============================================================================================================================================|
subroutine flux_split (ro, mx, my, mz, bx, by, bz, en,                                                                             &
   fro, fmx, fmy, fmz, fbx, fby, fbz, fen,                                                                                         &
   fro_s, fmx_s, fmy_s, fmz_s, fbx_s, fby_s, fbz_s, fen_s, nx, max_speed)
!==============================================================================================================================================|

   implicit none

   integer(4), intent(in) :: nx

   real(8), intent(in) :: max_speed
   real(8), dimension(nx), intent(in) :: ro, mx, my, mz, bx, by, bz, en
   real(8), dimension(nx), intent(in) :: fro, fmx, fmy, fmz, fbx, fby, fbz, fen
   real(8), dimension(nx, 2), intent(out) :: fro_s, fmx_s, fmy_s, fmz_s, fbx_s, fby_s, fbz_s, fen_s

   integer(4) :: i

!----------------------------------------------------------------------------------------------------------------------------------------------|

   do i = 1, nx
      fro_s(i, 1) = (fro(i) + max_speed * ro(i)) * 0.5d0
      fmx_s(i, 1) = (fmx(i) + max_speed * mx(i)) * 0.5d0
      fmy_s(i, 1) = (fmy(i) + max_speed * my(i)) * 0.5d0
      fmz_s(i, 1) = (fmz(i) + max_speed * mz(i)) * 0.5d0
      fbx_s(i, 1) = (fbx(i) + max_speed * bx(i)) * 0.5d0
      fby_s(i, 1) = (fby(i) + max_speed * by(i)) * 0.5d0
      fbz_s(i, 1) = (fbz(i) + max_speed * bz(i)) * 0.5d0
      fen_s(i, 1) = (fen(i) + max_speed * en(i)) * 0.5d0
      fro_s(i, 2) = (fro(i) - max_speed * ro(i)) * 0.5d0
      fmx_s(i, 2) = (fmx(i) - max_speed * mx(i)) * 0.5d0
      fmy_s(i, 2) = (fmy(i) - max_speed * my(i)) * 0.5d0
      fmz_s(i, 2) = (fmz(i) - max_speed * mz(i)) * 0.5d0
      fbx_s(i, 2) = (fbx(i) - max_speed * bx(i)) * 0.5d0
      fby_s(i, 2) = (fby(i) - max_speed * by(i)) * 0.5d0
      fbz_s(i, 2) = (fbz(i) - max_speed * bz(i)) * 0.5d0
      fen_s(i, 2) = (fen(i) - max_speed * en(i)) * 0.5d0
   enddo

!----------------------------------------------------------------------------------------------------------------------------------------------|
   return
end subroutine flux_split
